package com.zz.admin.userManagement.controller;

import com.zz.admin.userManagement.dto.UserDto;
import com.zz.admin.userManagement.service.UserService;
import java.util.List;
import com.zz.common.base.dto.PageListResultDto;
import com.zz.common.base.dto.ResponseDTO;
import com.zz.common.base.dto.ResultDto;
import com.zz.common.constants.ApiConstants;

import io.swagger.annotations.Api;
import jakarta.annotation.Resource;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * 用户表 服务接口类
 * @author zhang.lei
 * @since 2025-04-08 19:52:27
 */
@Api(tags = "用户表服务接口类")
@RestController
@RequestMapping("user-management/v1.0/user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/query-with-page", method = RequestMethod.POST)
    @ApiOperation(value = "用户表-分页查询", notes = "传入分页信息")
    public PageListResultDto<UserDto> queryWithPage(@RequestBody UserDto userDto) {
        PageListResultDto<UserDto> res;
        res = userService.queryWithPage(userDto, userDto.getQueryParam());
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/query-with-no-page", method = RequestMethod.POST)
    @ApiOperation(value = "用户表-不分页查询", notes = "传入查询条件信息")
    public ResponseDTO<List<UserDto>> queryWithNoPage(@RequestBody UserDto userDto) {
        ResponseDTO<List<UserDto>> res = new ResponseDTO<>();
        res.setData(userService.queryWithNoPage(userDto));
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "用户表-查询ById", notes = "传入id")
    public ResponseDTO<UserDto> queryById(@PathVariable("id") String id) {
        ResponseDTO<UserDto> res = new ResponseDTO<>();
        UserDto result = userService.queryById(id);
        res.setData(result);
        return res;
    }

    @RequestMapping(value = "/query-by-ids", method = RequestMethod.POST)
    @ApiOperation(value = "用户表-查询ByIds", notes = "传入ids")
    public ResponseDTO<List<UserDto>> queryByIds(@RequestBody List<String> ids) {
        ResponseDTO<List<UserDto>> res = new ResponseDTO<>();
        res.setData(userService.queryByIds(ids));
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "用户表-创建", notes = "创建")
    public ResultDto save(@RequestBody UserDto userDto) {
        ResultDto res = new ResultDto();
        userService.save(userDto);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/save-batch", method = RequestMethod.POST)
    @ApiOperation(value = "用户表-创建", notes = "创建")
    public ResultDto saveBatch(@RequestBody List<UserDto> userDtos) {
        ResultDto res = new ResultDto();
        userService.saveBatch(userDtos);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    @ApiOperation(value = "用户表-修改", notes = "修改")
    public ResultDto modify(@RequestBody UserDto userDto) {
        ResultDto res = new ResultDto();
        userService.modify(userDto);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/modify-batch", method = RequestMethod.POST)
    @ApiOperation(value = "用户表-修改", notes = "修改")
    public ResultDto modifyBatch(@RequestBody List<UserDto> userDtos) {
        ResultDto res = new ResultDto();
        userService.modifyBatch(userDtos);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "用户表-删除ById", notes = "传入id")
    public ResultDto delete(@PathVariable("id")  String id) {
        ResultDto res = new ResultDto();
        userService.delete(id);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/delete-batch", method = RequestMethod.POST)
    @ApiOperation(value = "用户表-批量删除", notes = "传入id")
    public ResultDto deleteBatch(@RequestBody List<String> ids) {
        ResultDto res = new ResultDto();
        userService.deleteBatch(ids);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

}